using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

/// <summary>
/// <para>教学节点，用于显示一个对话框，可自定义角色、文本、面板等元素</para>
/// </summary>
public class DialogTutorialNode : TutorialEventNode
{
	[JsonAttribute("char", "角色")]
	public TutorialUIManager.CharacterType _character = TutorialUIManager.CharacterType.Char1;
	[JsonAttribute("tId", "文本")]
	public string _text = "";
	[JsonAttribute("acty", "自定义面板大小和方位")]
	public bool _activityPanel = true;
	[JsonAttribute("rect", "区域(屏幕百分比)", "acty")]
	public Rect _panelRect = new Rect();
	[JsonAttribute("cont", "显示点击继续", "acty")]
	public bool _isClickContinue = true;
	[JsonAttribute("cpos", "角色方位", "acty")]
	public TutorialUIManager.CharacterPos _charPos = TutorialUIManager.CharacterPos.Left;
	[JsonAttribute("hdtb", "隐藏角色", "acty")]
	public bool _hideChar = false;

    [JsonAttribute("hmask", "是否有遮罩(有遮罩才能响应跳转事件")]
    public bool _hasMask = false;

    [JsonAttribute("hstag", "是否响应跳转事件", "hmask")]
    public bool _canSwitchTag = false;

    protected override void Init()
	{
		var dialogPage = TutorialUIManager.Instance.ShowDialog(_activityPanel ? TutorialUIManager.DialogType.Anywhere : TutorialUIManager.DialogType.Bottom, 
		                                      _charPos, _character, TextReadUtils.GetRightTextFromText(_text), _isClickContinue, _panelRect, _hideChar);
        if (_hasMask)
        {
            var img = dialogPage.GetComponent<Image>();
            img.raycastTarget = true;
            if (_canSwitchTag)
            {
                var tutorialClick = dialogPage.GetComponent<TutorialClick>();
                tutorialClick.Node = this;
            }
            
        }else
        {
            var tutorialClick = dialogPage.GetComponent<TutorialClick>();
            tutorialClick.Node = null;
            var img = dialogPage.GetComponent<Image>();
            img.raycastTarget = false;
        }
    }

	protected override void Cancel()
	{
		TutorialUIManager.Instance.HideDialog();
	}
}
